package com.example.nacosclientrabbit.controller;


import com.example.nacosclientrabbit.entity.Message;
import com.example.nacosclientrabbit.repository.SendRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@Slf4j
@RequestMapping("mq")
@RestController
public class SendController {

    @Autowired
    private SendRepository sendRepository;


    @RequestMapping("sendMessage")
    public void sendMessage(){
        Message message = new Message();
        log.info("start");
        message.setId(1L);
        message.setSync(false);
        message.setType(0);
        message.setRoutingKey("pc");
        message.setExchange("pcFanoutExchange");
        message.setUrl("http://127.0.0.1:8088/test");
        HashMap<String, Object> map = new HashMap<>();
        map.put("data", "测试数据");
        message.setBody(map);
        sendRepository.send(message);
    }

    @RequestMapping("/test")
    public String test(Object obj){
        log.info("obj:{}", obj);
        log.info("接收到任务");
        return "success";
    }
}
